﻿//地图JS
var ISS_MAP = {
    version: '1.0'
};

//公共常量
ISS_MAP.nearByMap = '';

//无限滚动变量
ISS_MAP.sroll = {
    //点击第一次页面执行
    flag_order_tab1: true,
    //当前tab标签，0：门票 1：酒店 2：餐厅
    current_tabindex: 0,
    //定义每页的页数
    size: 10,
    //每个tab的当前页
    index_tab0: 1,
    index_tab1: 1,
    index_tab2: 1,
    //删除滚动后重新添加滚动
    flag_InfiniteScroll: true,
    //是否需要滚动加载 
    flag_needScroll: true,
    //滚动事件只执行一次
    flag_execute: false
};

//有数据正在加载
ISS_MAP.Loading = false;

//查询内容 
ISS_MAP.Keyword = "";

//地图初始化
ISS_MAP.Init = function () {
    //定义地图
    ISS_MAP.nearByMap = new BMap.Map("map-box", { enableMapClick: false });
    //启用滚轮放大缩
    ISS_MAP.nearByMap.enableScrollWheelZoom();
    //定义地图风格
    ISS_MAP.nearByMap.setMapStyle({ style: ISS_MAP_TYPE });
    //添加缩放控件
    var navigationControl = new BMap.NavigationControl({
        //靠左上角位置
        anchor: BMAP_ANCHOR_BOTTOM_RIGHT,
        //LARGE类型
        type: BMAP_NAVIGATION_CONTROL_ZOOM
    });
    ISS_MAP.nearByMap.addControl(navigationControl);
    // 添加定位控件
    var geolocationControl = new BMap.GeolocationControl();
    geolocationControl.addEventListener("locationSuccess", function (e) {
        // 定位成功事件
        ISS_MAP_LOCAL_LNG = e.point.lng;
        ISS_MAP_LOCAL_LAT = e.point.lat;
    });
    geolocationControl.addEventListener("locationError", function (e) {
        // 定位失败事件
    });
    ISS_MAP.nearByMap.addControl(geolocationControl);
    //绑定地理位置
    var point = new BMap.Point(ISS_MAP_CENTER_LNG, ISS_MAP_CENTER_LAT);
    ISS_MAP.nearByMap.centerAndZoom(point, 13);
    //搜索栏
    var mySearchbar = myApp.searchbar('.searchbar', {
        searchList: '.list-block-search',
        searchIn: '.item-title',
        customSearch: true
    });
    //初始化进入
    ISS_MAP.PickModal();
    $("#pickbar")[0].style.height = "42%";
    $("#map-box")[0].style.height = "58%";

    //无限滚动 加载数据
    //第一次加载显示index_tab1，已付款的
    if (ISS_MAP.sroll.flag_order_tab1 == true) {
        //LoadAll("", ISS_MAP.sroll.index_tab0, ISS_MAP.sroll.current_tabindex);
        LocalGeocoder();
        ISS_MAP.sroll.flag_order_tab1 = false;
    }
};

//设置地图中心店
ISS_MAP.SetCenter = function (lng, lat, zoom) {
    var point = new BMap.Point(lng, lat);
    ISS_MAP.nearByMap.centerAndZoom(point, zoom);
}

//Marker集合
ISS_MAP.Markers = [];

//绘点
ISS_MAP.DrawArc = function (longitude, latitude, paramFlag, n) {
    var point = new BMap.Point(longitude, latitude);
    //图标
    var v_offset_y = (n - 1) * 50;
    var c_myIcon = "";
    if (paramFlag == 1) {
        c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/Base/ico-map.png", new BMap.Size(25, 42), {
            offset: new BMap.Size(25, 29),
            imageOffset: new BMap.Size(-30, 0 - v_offset_y)
        });
    } else if (paramFlag == 2) {
        c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/Base/ico-map.png", new BMap.Size(25, 42), {
            offset: new BMap.Size(25, 29),
            imageOffset: new BMap.Size(-90, 0 - v_offset_y)
        });
    } else if (paramFlag == 3) {
        c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/Base/ico-map.png", new BMap.Size(25, 42), {
            offset: new BMap.Size(25, 29),
            imageOffset: new BMap.Size(-150, 0 - v_offset_y)
        });
    }
    var marker = new BMap.Marker(point, { icon: c_myIcon }); // 创建点
    ISS_MAP.Markers.push(marker); //添加到集合
    ISS_MAP.nearByMap.addOverlay(marker); //展示
    ISS_MAP.nearByMap.setZoom(11);
    //弹出PickModal
    ISS_MAP.PickModal();
}

//跳转事件
ISS_MAP.MapGoto_Point = null;
ISS_MAP.MapGoto_Type = null;
 ISS_MAP.MapGoto=   function clickFunc() {
        var name= "未知";
        if(ISS_MAP.MapGoto_Type == "Toilet"){
           name="公厕";
        }else if(ISS_MAP.MapGoto_Type == "Bike"){
           name="自行车";
        }else if(ISS_MAP.MapGoto_Type == "Park"){
           name="停车场";
        }else if(ISS_MAP.MapGoto_Type == "Hospital"){
           name="医院";
        }else if(ISS_MAP.MapGoto_Type == "PassengerStation"){
           name="长途汽车站";
        }else if(ISS_MAP.MapGoto_Type == "Logistics"){
           name="物流快递";
        }else if(ISS_MAP.MapGoto_Type == "AutoMobile"){
           name="汽修厂";
        }else if(ISS_MAP.MapGoto_Type == "Gymnasium"){
           name="体育馆游乐园";
        }else if(ISS_MAP.MapGoto_Type == "Barbucue"){
           name="烧烤夜市";
        }else if(ISS_MAP.MapGoto_Type == "Market"){
           name="商场";
        }else if(ISS_MAP.MapGoto_Type == "Attrac"){
           name="景点";
        }
        var param = "?name=" + name + "&lng=" + ISS_MAP.MapGoto_Point.lng + "&lat=" + ISS_MAP.MapGoto_Point.lat;
        var hrefstr = "/Common/website/view/map/IframeForGoto.html" + param;
        window.parent.MapClickJump(hrefstr, param);
}

ISS_MAP.DrawArcConst = function (points , paramFlag) {
    //图标
    var c_myIcon = "";
    if (paramFlag == "Toilet") {
        c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/ConstMap/toilet@2x.png", new BMap.Size(47, 54), {
            offset: new BMap.Size(25, 29),
        });
    } else if (paramFlag == "Bike") {
        c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/ConstMap/bicycle@2x.png", new BMap.Size(47, 54), {
            offset: new BMap.Size(25, 29),
        });
    } else if (paramFlag == "Park") {
        c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/ConstMap/park@2x.png", new BMap.Size(47, 54), {
            offset: new BMap.Size(25, 29),
        });
    }else if (paramFlag == "Hospital") {
        c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/ConstMap/hospital@2x.png", new BMap.Size(47, 54), {
            offset: new BMap.Size(25, 29),
        });
    }else if (paramFlag == "PassengerStation") {
        c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/ConstMap/station@2x.png", new BMap.Size(47, 54), {
            offset: new BMap.Size(25, 29),
        });
    }else if (paramFlag == "Logistics") {
        c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/ConstMap/delivery@2x.png", new BMap.Size(47, 54), {
            offset: new BMap.Size(25, 29),
        });
    }else if (paramFlag == "AutoMobile") {
        c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/ConstMap/repair@2x.png", new BMap.Size(47, 54), {
            offset: new BMap.Size(25, 29),
        });
    }else if (paramFlag == "Gymnasium") {
        c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/ConstMap/gym@2x.png", new BMap.Size(47, 54), {
            offset: new BMap.Size(25, 29),
        });
    }else if (paramFlag == "Barbucue") {
        c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/ConstMap/barbecue@2x.png", new BMap.Size(47, 54), {
            offset: new BMap.Size(25, 29),
        });
    }else if (paramFlag == "Market") {
        c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/ConstMap/supermark@2x.png", new BMap.Size(47, 54), {
            offset: new BMap.Size(25, 29),
        });
    }else if (paramFlag == "Attrac") {
        c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/ConstMap/spot@2x.png", new BMap.Size(47, 54), {
            offset: new BMap.Size(25, 29),
        });
    }
    $.each(points, function (index, value) {
        var pointBD = new BMap.Point(value.lon, value.lat);
        //图标
        var marker = new BMap.Marker(pointBD, { icon: c_myIcon }); // 创建点
        ISS_MAP.nearByMap.addOverlay(marker); //展示
        ISS_MAP.MapGoto_Point = pointBD;
        ISS_MAP.MapGoto_Type = paramFlag;
        marker.addEventListener("click", ISS_MAP.MapGoto);
    });
    if (points && points.length > 0) {
        ISS_MAP.SetCenter(points[0].lon, points[0].lat, 13);
    }
}

//清除地图覆盖物
ISS_MAP.ClearArc = function () {
    ISS_MAP.nearByMap.clearOverlays();
}

////Preloader show
//ISS_MAP.ShowPre = function () {
//    $$("#preloader").css("display", "block");
//}

////Preloader hide
//ISS_MAP.HidePre = function () {
//    $$("#preloader").css("display", "none");
//}

//Pick Modal
ISS_MAP.PickModal = function () {
    myApp.pickerModal(".picker-1");
}

//framework7的弹出层
/* 变量 */
var map = "map/map.html";

//地图导航
var contactsCallback_map = myApp.onPageInit('mapthree', function (page) {
    //初次加载的时候page为undefine,所以page不空的时候就是返回的,需要动态加载
    if (page) {
        //动态加载JS,只需重新绑定事件,方法可以直接调用
        var oHead = document.getElementsByTagName('HEAD').item(0);
        var oScript = document.createElement("script");
        oScript.type = "text/javascript";
        oScript.src = "/Common/website/assets/js/map/NearBy/Map_Tour.js";
        oHead.appendChild(oScript);
        //标识ISS_MAP.sroll.flag_order_tab1,因为返回的时候要重新加载
        ISS_MAP.sroll.flag_order_tab1 = true;
    }
    //初始化
    ISS_MAP.Init();
});

/* 初始化  */
function initData() {
    var href = window.location.href;
    if (href.indexOf(map) > -1) {
        contactsCallback_map.trigger();
    }
}

initData();